package com.enlorenz.common.geo.analyzer.distance.calc;

import com.enlorenz.common.geo.analyzer.distance.IDataCalculator;
import com.enlorenz.common.geo.util.PublicUtil;
import com.enlorenz.core.objectmodel.attribute.MileCountAttribute;
import com.enlorenz.core.objectmodel.entity.IStatus;

/**
 * 里程计算
 * @author Karma
 *
 */
public class MileDisCalc implements IDataCalculator{
	private IStatus preStatus;
	private double totalDis=0;

	@Override
	public void doIterator(int total, int index, IStatus status) {
		
		if(null == preStatus){
			preStatus=status;
		}else{
			MileCountAttribute mca=(MileCountAttribute)status;
			MileCountAttribute pMca=(MileCountAttribute)preStatus;
			
			if(!PublicUtil.isStrEmpty(pMca.getMileCount())
					&&!PublicUtil.isStrEmpty(mca.getMileCount())){
				Double preDis=Double.valueOf(pMca.getMileCount());
				Double nowDis=Double.valueOf(mca.getMileCount());
				
				if(nowDis>=preDis){
					totalDis+=(nowDis-preDis);
				}
			}
			
			preStatus=status;
		}
	}

	@Override
	public String getResult() {
		return String.valueOf(totalDis);
	}

}
